<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数的参数</title>
</head>
<body>
<script type="text/javascript">
  // 函数的定义和调用
  // 函数的定义：function 函数名（）{函数体}
  // 函数的调用：函数名（）
  // 案例1：求两个数的和
  function num(a, b) {
    var c = a + b;
    document.write("a + b = " + c + "<\hr>");
  }
  num(1, 2);

  function addArray(a, b, c) {
      var arr =[];
      arr[0] = a;
      arr[1] = b;
      arr[2] = c;
      /*//判断参数a,b,c是不是字符串
      if(typeof(a)=="string" && typeof(b)=="string" && typeof(c)=="string") {
          document.write(a + b+ c);
      }
      if (typeof(a)=="number" && typeof(b)=="number" && typeof(c)=="number") {
          document.write("a+b+c=" + (a+b+c));
      } else {
          for(var i=0; i<arr.length; i++) {
              document.write("arr[" + i + "] = " + arr[i] + ",");
          }
      }*/
      var num=0;
      var str="";
      //循环数组，将里面number部分全部相加
      for(var i=0; i<arr.length; i++) {
          if (typeof(arr[i])=="number") {
              num += arr[i];
          }
          if (typeof(arr[i])=="string") {
              str = str + arr[i];
          }
      }
      if(str == "") str = "NULL";
      if(num == 0) num = 0;
      document.write("数字部分的和为 = " + num + "<br>");
      document.write("字符串组装为 = " + str + "<br>");
      document.writeln("<\hr>");
  }
  addArray(20, 30, 50);
  addArray("这是","调用","函数");
  a
</script>
</body>
</html>